/*
 * @Author: 清酒吖
 * @Date: 2022-01-17 15:57:11
 * @Email:  
 * @LastEditors:  
 * @LastEditTime: 2022-02-07 15:56:16
 * @Description: 
 * @version: x 1.0
 */
import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
import router from '@/router'

// create an axios instance
const service = axios.create({
  baseURL: "http://localhost:9527", // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// request interceptor 请求拦截器
service.interceptors.request.use(
  function(config){
    // 全局的将jwt令牌放入请求头中
    config.headers.token = localStorage.getItem("token")||"";
    
    return config;
  }
)

// response interceptor 响应拦截器
service.interceptors.response.use(
  function(res){
    var response = res.data;
    if (response.bcCode == '403'){ // 没有权限访问
      // 跳转到403页面
      router.push({path:'/403'})

    }

    return response;
  }
)

export default service
